package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author itlxc
 * @since 2024-08-06
 */
@RestController
@RequestMapping("nursing_project")
@RequiredArgsConstructor
@Slf4j
@Api(tags = "护理项目相关接口")
public class NursingProjectController {

    private final NursingProjectService nursingProjectService;

    private final NursingProjectMapper nursingProjectMapper;


    /**
     * 分页查询护理项目
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping
    @ApiOperation(value = "分页查询护理项目")
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(
            @RequestParam(value = "name",required = false) String name,
            @RequestParam(value = "status",required = false) Integer status,
            @RequestParam(value = "pageNum",defaultValue = "1")Integer pageNum,
            @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize
    ) {
        log.info("分页查询护理项目：{}，{}，{}，{}", name, status, pageNum, pageSize);
        return ResponseResult.success(nursingProjectService.getByPage(pageNum,pageSize,name,status));
    }

    /**
     * 添加护理项目
     * @param nursingProjectDTO
     * @return
     */
    @PostMapping
    @ApiOperation(value = "添加护理项目")
    public ResponseResult add(@RequestBody NursingProjectDto nursingProjectDTO) {
        log.info("添加护理项目：{}", nursingProjectDTO);
        nursingProjectService.add(nursingProjectDTO);
        return ResponseResult.success();
    }

    /**
     * 更新护理项目信息
     *
     * @param nursingProjectDTO 护理项目数据传输对象
     * @return 操作结果
     */
    @PutMapping
    @ApiOperation(value = "更新护理项目信息")
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDTO) {
        log.info("更新护理项目信息：{}", nursingProjectDTO);
        nursingProjectService.updateProject(nursingProjectDTO);
        return ResponseResult.success();
    }

    /**
     * 根据编号查询护理项目信息
     *
     * @param id 护理项目编号
     * @return 护理项目信息
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据编号查询护理项目信息")
    public ResponseResult<NursingProjectVo> getById(
            @PathVariable("id") Long id) {
        log.info("根据编号查询护理项目信息：{}", id);
        NursingProjectVo nursingProjectVO = nursingProjectMapper.getById(id);
        return ResponseResult.success(nursingProjectVO);
    }

    /**
     * 查询所有护理项目
     *
     * @return 护理项目列表
     */
    @GetMapping("/all")
    @ApiOperation(value = "查询所有护理项目")
    public ResponseResult<List<NursingProject>> getAllNursingProject() {
        log.info("查询所有护理项目");
        List<NursingProject> NursingProjects = nursingProjectService.all();
        return ResponseResult.success(NursingProjects);
    }

    /**
     * 启用或禁用护理项目
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "启用或禁用护理项目")
    public ResponseResult enableOrDisable(
            @PathVariable Long id,
            @PathVariable Integer status) {
        log.info("启用或禁用护理项目：{}，{}", id, status);
        nursingProjectService.enableOrDisable(id, status);
        return ResponseResult.success();
    }

    /**
     * 删除护理项目信息
     *
     * @param id 护理项目编号
     * @return 操作结果
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除护理项目信息")
    public ResponseResult deleteById(@PathVariable("id") Long id) {
        log.info("删除护理项目信息：{}", id);
        nursingProjectService.deleteById(id);
        return ResponseResult.success();
    }
}
